import 'package:app/models/ChatModel.dart';
import 'package:app/pages/CameraPage.dart';
import 'package:flutter/material.dart';

import '../pages/ChatPage.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key, required this.chatmodels, required this.sourchat})
      : super(key: key);

  final List<ChatModel> chatmodels;
  final ChatModel sourchat;

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen>
    with SingleTickerProviderStateMixin {
  late TabController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TabController(length: 4, vsync: this, initialIndex: 0);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("wahts app"),
        actions: [
          IconButton(onPressed: () {}, icon: const Icon(Icons.search)),
          PopupMenuButton(onSelected: (value) {
            print(value);
          }, itemBuilder: (BuildContext context) {
            return [
              PopupMenuItem(child: Text("new group"), value: "new group"),
              PopupMenuItem(
                  child: Text("new broadcast"), value: "new broadcast"),
              PopupMenuItem(child: Text("whatapp web"), value: "whatapp web"),
              PopupMenuItem(
                  child: Text("started message"), value: "started message"),
              PopupMenuItem(child: Text("setting"), value: "setting"),
            ];
          })
        ],
        bottom: TabBar(
          controller: _controller,
          indicatorColor: Colors.white,
          tabs: [
            Tab(
              icon: Icon(Icons.camera_alt),
            ),
            Tab(
              text: "chats",
            ),
            Tab(
              text: "status",
            ),
            Tab(
              text: "calls",
            ),
          ],
        ),
      ),
      body: TabBarView(
        controller: _controller,
        children: [
          CameraPage(),
          ChatPage(chatmodels: widget.chatmodels, sourchat: widget.sourchat),
          Text("status"),
          Text("calls"),
        ],
      ),
    );
  }
}
